package com.example.demo.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@ControllerAdvice
@ResponseBody
public class ErrorAdvice {
    @ExceptionHandler(Exception.class)
    public Object Exception(Exception e) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("success",200);
        map.put("status",-1);
        map.put("message","出现异常!" + e.getMessage());
        return map;
    }
    @ExceptionHandler(NullPointerException.class)
    public Object nullPointerException(NullPointerException e) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("success",200);
        map.put("status",-1);
        map.put("message","空指针异常!");
        return map;
    }
}
